package org.lsy;

/**
 * @author sazabi
 * @version 1.0
 * @date 2021/7/12
 */
public class CustomerThread extends Thread{

    private final Lock lock1;

    private final Lock lock2;

    public CustomerThread(Lock lock1, Lock lock2) {
        this.lock1 = lock1;
        this.lock2 = lock2;
    }

    @Override
    public void run() {
        synchronized (lock1) {
            Thread currentThread = Thread.currentThread();
            System.out.println(currentThread + "获取到锁" + lock1);
            try {
                Thread.sleep(2*1000);
            } catch (Exception e) {
                e.printStackTrace();
            }
            synchronized (lock2) {
                System.out.println(currentThread + "获取到锁" + lock2);
            }
        }
    }
}
